package com.aw.guiguzi.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import com.aw.guiguzi.R
import com.aw.guiguzi.bean.NumItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class BettingReConfirmAdapter :
    BaseQuickAdapter<NumItemBean, BaseViewHolder>(R.layout.adapter_betting_reconfirm) {
    private var mList: MutableList<NumItemBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: NumItemBean) {
        helper.setText(R.id.tv_nums, bean.name)
            .addOnClickListener(R.id.cBox_status)
        val checkBox = helper.getView<ImageView>(R.id.cBox_status)
        if (bean.isDouble()) {
            checkBox.background = mContext.resources.getDrawable(R.drawable.icon_checkbox_on)
        } else {
            checkBox.background = mContext.resources.getDrawable(R.drawable.icon_checkbox_off)
        }
        val tv_nums = helper.getView<TextView>(R.id.tv_nums)
        if (bean.isAllowDouble()) {
            checkBox.isEnabled = true
            helper.setTextColor(
                R.id.tv_nums,
                mContext.resources.getColor(com.aw.baselib.R.color.black)
            )
        } else {
            checkBox.isEnabled = false
            checkBox.background = mContext.resources.getDrawable(R.drawable.aw_bg_gray_big_cornor)
            tv_nums.paint.flags =
                Paint.STRIKE_THRU_TEXT_FLAG or Paint.ANTI_ALIAS_FLAG // 设置中划线并加清晰
            helper.setTextColor(
                R.id.tv_nums,
                mContext.resources.getColor(com.aw.baselib.R.color.gray)
            )
        }
    }

    fun addAllData(dataList: MutableList<NumItemBean>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}